package com.ztesoft.web.filecommon.customdb.dao;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.ztesoft.web.common.DMSConstant.Status;
import com.ztesoft.web.filecommon.customdb.dao.mapper.IDmFCustomMapper;
import com.ztesoft.web.filecommon.db.po.DmFDetailPO;
import com.ztesoft.web.filecommon.db.po.DmFPO;

/**
 * @Description 文件脚本操作轨迹表表自定义DAO
 * @author lin.weibin@zte.com.cn
 * @date 2015年8月6日 下午8:15:16
 * @since 1.0
 *
 */
@Repository
public class DmFCustomDao extends SqlSessionDaoSupport {

    @Resource(name = "majorSqlSessionTemplate")
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        super.setSqlSessionTemplate(sqlSessionTemplate);
    }
    
    public IDmFCustomMapper getMapper() {
    	return getSqlSession().getMapper(IDmFCustomMapper.class);
    }
    
    /**
     * 获取状态为00T,00P,01P,02P的文件脚本操作轨迹记录
     * @param dmInfoId
     * @param dmStrategyId
     * @return
     */
    public List<DmFPO> selectByInfoId(Integer dmInfoId,Integer dmStrategyId){ 
    	return getMapper().selectByInfoId(dmInfoId,dmStrategyId);
    }

	public List<DmFDetailPO> selectByTrackId(Integer trackId, Integer dmStrategyId, Integer limit, String state) {
		return getMapper().selectByTrackId(trackId,dmStrategyId,limit,state);
	}

	public int updateDetailState(Integer dmStrategyId,List<Integer> backList, String state) {
		StringBuffer updateConditions = new StringBuffer();
		if(backList.size()>0){
			updateConditions.append(" DETAIL_ID in ( ").append(StringUtils.join(backList.toArray(),",")).append(" ) ");
		}else{
			updateConditions.append(" 1=2 ");
		}
		return getMapper().updateDetailState(dmStrategyId,updateConditions.toString(),state);
	}

	

	public int updateFieSizeAndCountForDMF(Integer dmStrategyId,
			BigDecimal sumSize, int sunNum, String packageName, Integer trackId) {
		return getMapper().updateFieSizeAndCountForDMF(dmStrategyId,sumSize,sunNum,packageName,trackId);
		
	}

	public int updateFieSizeAndCountForStage(BigDecimal sumSize, int sunNum,
			Integer dmInfoId) {
		return getMapper().updateFieSizeAndCountForStage(sumSize,sunNum,dmInfoId);
		
	}

	public int updatedmfStateByTrackId(Integer strategyId, int trackId,
			String backUpState) {
		return getMapper().updatedmfStateByTrackId(strategyId,trackId,backUpState);
		
	}
	public int updatedmfByTrackId(Integer strategyId, Integer trackId, String state){
		return getMapper().updatedmfStateByTrackId(strategyId,trackId,state);
	}
	
	public int updatedmfStateByTaskId(Integer strategyId, Integer dmTaskId,
			String backUpState) {
		return getMapper().updatedmfStateByTaskId(strategyId,dmTaskId,backUpState);
		
	}

	public int updateDetailStateByTask(Integer strategyId, Integer dmTaskId,
			String backUpState) {
		return getMapper().updateDetailStateByTask(strategyId,dmTaskId,backUpState);
		
	}

	public int updateDetailStateByTrackId(Integer strategyId, Integer trackId,
			String backUpState) {
		return getMapper().updateDetailStateByTrackId(strategyId,trackId,backUpState);
		
	}

	public int updatedmfStateByInfoId(Integer strategyId, Integer dmInfoId,
			String state) {
		return getMapper().updatedmfStateByInfoId(strategyId,dmInfoId,state);
		
	}

	public int updateDetailStateByInfoId(Integer strategyId, Integer dmInfoId,
			String state) {
		return getMapper().updateDetailStateByInfoId(strategyId,dmInfoId,state);
		
	}

}
